package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.Brand;
import com.qingcheng.service.goods.BrandService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: wy
 * @Date:2019/9/9 23:32
 */
@Controller
@RequestMapping("/brand")
@ResponseBody
public class BrandController {

    @Reference
    private BrandService brandService;
      @RequestMapping("/findAll")
    public List<Brand> findAll(){
          List<Brand> brandList = brandService.findAll();
          return  brandList;
      }
      /*分页查询所有*/
     @GetMapping("/findPage")/* 只能通过get请求拿到参数*/
      public PageResult<Brand> findPage(Integer page,Integer size){
          PageResult<Brand> pageResult= brandService.findPage(page, size);
                   return pageResult;
      }

      /*post请求,条件查询*/
    @RequestMapping("/findList")
       public List<Brand> findList(@RequestBody Map<String,Object> map){
           return brandService.findList(map);

       }

       /*分页+条件*/
        @RequestMapping("/findPageCondition")
           public PageResult<Brand> findPageCondition(@RequestBody Map<String,Object> map,Integer page,Integer size){

            return  brandService.findPageCondition(map,page,size);

        }

        /*根据id查找*/
         @GetMapping("/findById")
          public Brand findById(Integer id){
            return brandService.findById(id);
         }

          @RequestMapping("/addBrand")
          public Result add(@RequestBody Brand brand){
              int add = brandService.add(brand);
               return  new Result();
          }

           @RequestMapping("/updateBrand")
           public Result update(@RequestBody Brand brand){
             /*返回值后期处理*/
               int update = brandService.update(brand);
                return  new Result();
           }

           @RequestMapping("/deleteBrand")
             public Result delete(Integer id){
               int delete = brandService.delete(id);
                  return  new Result();
           }
}
